#ifndef MACRO_H
#define MACRO_H

#include "FT32F10x.h"

// GPIOA
#define AD_TEMP		GPIO_Pin_7		// 水温检测
#define JK_LP		GPIO_Pin_8		// 脚控，口腔灯，低电平有效

// GPIOB
#define OUT_H		GPIO_Pin_1		// 加热输出，低电平有效
#define I_OUT		GPIO_Pin_12		// 水杯检测，低电平有效,与H_C是一样的
#define AJ_C		GPIO_Pin_13 	// CUP按键输入，低电平按下
#define AJ_W		GPIO_Pin_14 	// Water按键输入，低电平按下
#define JK_UP		GPIO_Pin_15  	// UP   脚控输入，低电平有效

// GPIOC
#define AD_WATER	GPIO_Pin_1		// PC1-->ADC123_IN11
#define AD_CUP		GPIO_Pin_2		// PC2-->ADC123_IN12
#define AD_LAMP		GPIO_Pin_5		// PC5-->ADC123_IN15
#define JK_DN		GPIO_Pin_6  	// 脚控, DN   ，低电平有效				P34
#define AJ_RESET	GPIO_Pin_7  	// 按键，RESET，低电平有效				P17
#define JK_BU		GPIO_Pin_8  	// 脚控，靠背上升，低电平有效				P14
#define JK_BD		GPIO_Pin_9		// 脚控，靠背下降，低电平有效     			P11
#define OUT_W		GPIO_Pin_13		// 输出, Water，低电平有效
#define OUT_C		GPIO_Pin_14		// 输出，CUP，低电平有效
#define OUT_F		GPIO_Pin_15		// 输出，LAMP，低电平有效


// GPIOA操作宏定义




// GPIOC操作宏定义


// ADC 通道
#define AD_TEMP_ch		ADC_Channel_7	// PA7-->ADC12_IN7 
#define AD_WATER_ch		ADC_Channel_11	// PC1-->ADC123_IN11
#define AD_CUP_ch		ADC_Channel_12	// PC2-->ADC123_IN12
#define AD_LAMP_ch		ADC_Channel_15	// PC5-->ADC123_IN15


// LED宏定义


// Motor宏定义


// 限位器宏定义


// 遇阻开关(紧急按钮)


// 机椅互锁

// 脚控

// CUP控制
#define mCupOn()		GPIO_SetBits(GPIOB, OUT_C)		// 
#define mCupOff()		GPIO_ResetBits(GPIOB, OUT_C)

// Disinf控制
#define mDisinfOn()		//GPIO_SetBits(GPIOA, OUT_XD)		// 
#define mDisinfOff()	//GPIO_ResetBits(GPIOA, OUT_XD)


// Water控制
#define mWaterOn()		GPIO_SetBits(GPIOC, OUT_W)		// 
#define mWaterOff()		GPIO_ResetBits(GPIOC, OUT_W)


#define isSeatFault()	(SysBit_1.Bits.SeatFault)
#define sSetSeatFault()	SysBit_1.Bits.SeatFault = 1;\
						ubFaultCode = cSeatComFault
#define sClrSeatFault()	SysBit_1.Bits.SeatFault = 0;\
						if(ubFaultCode == cSeatComFault)\
						{							    \
							ubFaultCode = cFaultNone;   \
						}

						
#define isStBkFault()	(SysBit_1.Bits.StBkFault)
#define sSetStBkFault()	SysBit_1.Bits.StBkFault = 1;\
						ubFaultCode = cStBkComFault
#define sClrStBkFault()	SysBit_1.Bits.StBkFault = 0;\
						if(ubFaultCode == cSeatComFault)\
						{							    \
							ubFaultCode = cFaultNone;   \
						}







#define mLedSetOn()		LedMatrix2[ComDevice1].Bits.SET = 1;\
						LedMatrix2[ComMainBrd].Bits.SET = 1
#define mLedSetOff()	LedMatrix2[ComDevice1].Bits.SET = 0;\
						LedMatrix2[ComMainBrd].Bits.SET = 0


#define	mLedW1On()		LedMatrix1[ComDevice1].Bits.W1 = 1;\
						LedMatrix1[ComMainBrd].Bits.W1 = 1
#define	mLedW1Off()		LedMatrix1[ComDevice1].Bits.W1 = 0;\
						LedMatrix1[ComMainBrd].Bits.W1 = 0



#define	mLedW2On()		LedMatrix1[ComDevice1].Bits.W2 = 1;\
						LedMatrix1[ComMainBrd].Bits.W2 = 1
#define	mLedW2Off()		LedMatrix1[ComDevice1].Bits.W2 = 0;\
						LedMatrix1[ComMainBrd].Bits.W2 = 0



#define	mNeedSave()		SysBit_1.Bits.SetSaving = 1

#define mHeatLedOn()	LedMatrix1[ComDevice1].Bits.HEAT = 1;\
						LedMatrix1[ComMainBrd].Bits.HEAT = 1
#define mHeatLedOff()	LedMatrix1[ComDevice1].Bits.HEAT = 0;\
						LedMatrix1[ComMainBrd].Bits.HEAT = 0
#define	mGetHeatLed()	((LedMatrix1[ComDevice1].Bits.HEAT == 1) || (LedMatrix1[ComMainBrd].Bits.HEAT == 1))

#define mLampLedOn()	LedMatrix1[ComDevice1].Bits.LAMP = 1;\
						LedMatrix1[ComMainBrd].Bits.LAMP = 1
#define mLampLedOff()	LedMatrix1[ComDevice1].Bits.LAMP = 0;\
						LedMatrix1[ComMainBrd].Bits.LAMP = 0

#define mWatchLedOn()	LedMatrix2[ComDevice1].Bits.Watch = 1;\
						LedMatrix2[ComMainBrd].Bits.Watch = 1
#define mWatchLedOff()	LedMatrix2[ComDevice1].Bits.Watch = 0;\
						LedMatrix2[ComMainBrd].Bits.Watch = 0

#define mLpLedOn()		LedMatrix1[ComDevice1].Bits.Lp = 1;\
						LedMatrix1[ComMainBrd].Bits.Lp = 1
#define mLpLedOff()		LedMatrix1[ComDevice1].Bits.Lp = 0;\
						LedMatrix1[ComMainBrd].Bits.Lp = 0
						
#define mDocALedOn()	LedMatrix1[ComDevice1].Bits.A = 1;\
						LedMatrix1[ComMainBrd].Bits.A = 1
#define mDocALedOff()	LedMatrix1[ComDevice1].Bits.A = 0;\
						LedMatrix1[ComMainBrd].Bits.A = 0

#define mDocBLedOn()	LedMatrix1[ComDevice1].Bits.B = 1;\
						LedMatrix1[ComMainBrd].Bits.B = 1
#define mDocBLedOff()	LedMatrix1[ComDevice1].Bits.B = 0;\
						LedMatrix1[ComMainBrd].Bits.B = 0

#define mDocCLedOn()	LedMatrix1[ComDevice1].Bits.C = 1;\
						LedMatrix1[ComMainBrd].Bits.C = 1
#define mDocCLedOff()	LedMatrix1[ComDevice1].Bits.C = 0;\
						LedMatrix1[ComMainBrd].Bits.C = 0


#define sMotorLocked()	(LclBtnSts1.Bits.MotorLock == 1)	// 机椅互锁


#define mBtnUpTrg()     ((BtnMatrix2[ComDevice1].Bits.BtnUp == 1 && BtnMatrix2Old[ComDevice1].Bits.BtnUp == 0) ||\
                         (BtnMatrix2[ComMainBrd].Bits.BtnUp == 1  && BtnMatrix2Old[ComMainBrd].Bits.BtnUp == 0)  ||\
                         (FtCtrBtn.Bits.BtnUp == 1                  && FtCtrBtnOld.Bits.BtnUp == 0))
#define mBtnUpOn()      (BtnMatrix2[ComDevice1].Bits.BtnUp == 1 || BtnMatrix2[ComMainBrd].Bits.BtnUp == 1 ||\
                         FtCtrBtn.Bits.BtnUp == 1)

#define mBtnDnTrg()     ((BtnMatrix3[ComDevice1].Bits.BtnDn == 1 && BtnMatrix3Old[ComDevice1].Bits.BtnDn == 0) ||\
                         (BtnMatrix3[ComMainBrd].Bits.BtnDn == 1  && BtnMatrix3Old[ComMainBrd].Bits.BtnDn == 0)  ||\
                         (FtCtrBtn.Bits.BtnDn == 1                  && FtCtrBtnOld.Bits.BtnDn == 0))
#define mBtnDnOn()      (BtnMatrix3[ComDevice1].Bits.BtnDn == 1 || BtnMatrix3[ComMainBrd].Bits.BtnDn == 1 ||\
                         FtCtrBtn.Bits.BtnDn == 1)

#define mBtnBuTrg()     ((BtnMatrix2[ComDevice1].Bits.BtnBu == 1 && BtnMatrix2Old[ComDevice1].Bits.BtnBu == 0) ||\
                         (BtnMatrix2[ComMainBrd].Bits.BtnBu == 1  && BtnMatrix2Old[ComMainBrd].Bits.BtnBu == 0)  ||\
                         (FtCtrBtn.Bits.BtnBu == 1                  && FtCtrBtnOld.Bits.BtnBu == 0))
#define mBtnBuOn()      (BtnMatrix2[ComDevice1].Bits.BtnBu == 1 || BtnMatrix2[ComMainBrd].Bits.BtnBu == 1 ||\
                         FtCtrBtn.Bits.BtnBu == 1)

#define mBtnBnTrg()     ((BtnMatrix3[ComDevice1].Bits.BtnBn == 1 && BtnMatrix3Old[ComDevice1].Bits.BtnBn == 0) ||\
                         (BtnMatrix3[ComMainBrd].Bits.BtnBn == 1  && BtnMatrix3Old[ComMainBrd].Bits.BtnBn == 0)  ||\
                         (FtCtrBtn.Bits.BtnBn == 1                  && FtCtrBtnOld.Bits.BtnBn == 0))
#define mBtnBnOn()      (BtnMatrix3[ComDevice1].Bits.BtnBn == 1 || BtnMatrix3[ComMainBrd].Bits.BtnBn == 1 ||\
                         FtCtrBtn.Bits.BtnBn == 1)

#define mBtnWaterTrg()  ((BtnMatrix3[ComDevice1].Bits.BtnWater == 1 && BtnMatrix3Old[ComDevice1].Bits.BtnWater == 0) ||\
                         (BtnMatrix3[ComMainBrd].Bits.BtnWater == 1  && BtnMatrix3Old[ComMainBrd].Bits.BtnWater == 0)  ||\
                         (FtCtrBtn.Bits.BtnWater == 1                  && FtCtrBtnOld.Bits.BtnWater == 0))
#define mBtnWaterOn()   (BtnMatrix3[ComDevice1].Bits.BtnWater == 1 || BtnMatrix3[ComMainBrd].Bits.BtnWater == 1 ||\
                         FtCtrBtn.Bits.BtnWater == 1)  
#define mBtnCupTrg()    ((BtnMatrix3[ComDevice1].Bits.BtnCup == 1 && BtnMatrix3Old[ComDevice1].Bits.BtnCup == 0) ||\
                         (BtnMatrix3[ComMainBrd].Bits.BtnCup == 1  && BtnMatrix3Old[ComMainBrd].Bits.BtnCup == 0)  ||\
                         (FtCtrBtn.Bits.BtnCup == 1                  && FtCtrBtnOld.Bits.BtnCup == 0))
#define mBtnCupOn()     (BtnMatrix3[ComDevice1].Bits.BtnCup == 1 || BtnMatrix3[ComMainBrd].Bits.BtnCup == 1 ||\
                         FtCtrBtn.Bits.BtnCup == 1)  
#define mBtnSpiteTrg()  ((BtnMatrix2[ComDevice1].Bits.BtnSpite == 1 && BtnMatrix2Old[ComDevice1].Bits.BtnSpite == 0) ||\
                         (BtnMatrix2[ComMainBrd].Bits.BtnSpite == 1  && BtnMatrix2Old[ComMainBrd].Bits.BtnSpite == 0)  ||\
                         (FtCtrBtn.Bits.BtnSpite == 1                  && FtCtrBtnOld.Bits.BtnSpite == 0))
#define mBtnSpiteOn()   (BtnMatrix2[ComDevice1].Bits.BtnSpite == 1 || BtnMatrix2[ComMainBrd].Bits.BtnSpite == 1 ||\
                         FtCtrBtn.Bits.BtnSpite == 1)
                         
#define mBtnDisinfTrg() (FtCtrBtn.Bits.BtnDisinf == 1 && FtCtrBtnOld.Bits.BtnDisinf == 0)



#endif

